package com.powernode.controller;

import com.powernode.entity.Orders;
import com.powernode.service.OrdersService;
import com.powernode.vo.HttpResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 订单接口
 */
@Controller
@Slf4j
@RequestMapping("/goods")
public class OrdersController {

    @Resource
    private OrdersService ordersService;

    @GetMapping("/result/{id}")
    @ResponseBody
    public HttpResult selectSeckillReturn(@PathVariable(value = "id")Integer id){
        log.info("查询秒杀结果");
        Integer userId = 1001;
        Orders orders = ordersService.selectSeckillReturn(id , userId);
        if (orders == null) {
            return HttpResult.ERROR();
        }
        // 判断订单状态 是否为 1
        if (orders.getStatus() == 1) {
            return HttpResult.SUCCESS(orders);
        } else if (orders.getStatus() == 0) {
            return HttpResult.ERROR("待支付");
        } else {
            return HttpResult.ERROR("");
        }
    }
}
